#
# A simple script to check if svn permission setting is correct
#

SVN="svn --non-interactive "
ERROR_STR="Error (svn permission):"
OUTPUT_FILE="svn_perm_error.txt"

check_folder()
{
    folder=$1
    #See if folder exist
    if [[ -d ${folder} ]]
    then
        #See if we have permission to access this folder in svn
        ${SVN} ls ${folder} > /dev/null
        if [[ $? != 0 ]]
        then
            #Permission error!!
            echo "${ERROR_STR} Folder ${folder} have permission problem!" >> ${OUTPUT_FILE}
            return 1
        fi
        #See if this folder is already delete from svn server
    else
        echo "${ERROR_STR} Folder ${folder} not exist!" >> ${OUTPUT_FILE}
        return 1
    fi
    return 0
}

#==== app folder
svn_folder_list="
./app/
./app/chat/
./app/udev
./app/reg-tools
./app/telnetd
./app/udev
./app/usbmodeswitch
./app/booter
"

#==== exdrv folder
svn_folder_list+="
./exdrv/
./exdrv/aic3104
./exdrv/at88sc0104
./exdrv/beep
./exdrv/cx26828
./exdrv/ds3231
./exdrv/gv7601
./exdrv/i2c_core
./exdrv/i2c_module
./exdrv/inc
./exdrv/led
./exdrv/nvp1918
./exdrv/pca955
./exdrv/powerctl
./exdrv/reg_pro
./exdrv/ssp
./exdrv/tw286x
./exdrv/wifi
./exdrv/hios_mcc_usrdev
./exdrv/boot_device
./exdrv/hi_ir
"

#==== other top level folder
svn_folder_list+="
./scripts
./daemon
./build
"

#==== firmware
svn_folder_list+="
./firmware/busybox
./firmware/kernel
./firmware/uboot
"

#==== tool
svn_folder_list+="
./tool/htop
./tool/libpng
./tool/lua
./tool/ncurses
./tool/sig_tracer
./tool/zlib
"

#==== comp
svn_folder_list+="
./comp/audio/
./comp/audio/_include
./comp/audio/_aconf
./comp/audio/_adec
./comp/audio/_aenc
./comp/audio/_ai
./comp/audio/_ao
./comp/audio/adec
./comp/audio/aenc
./comp/audio/ai
./comp/audio/ao
./comp/base/
./comp/base/common
./comp/base/mshead
./comp/gui/
./comp/gui/app
./comp/gui/core
./comp/gui/extmgctrl
./comp/gui/inc
./comp/gui/mgi
./comp/mfs/
./comp/mfs/_include
./comp/mfs/_mfs_cddvd
./comp/mfs/_mfs_dev
./comp/mfs/_mfs_fat32
./comp/mfs/_mfs_file
./comp/mfs/_mfs_fs
./comp/mfs/docs
./comp/mfs/hard_raid
./comp/mfs/mfs_backup
./comp/mfs/mfs_comm
./comp/mfs/mfs_ctrl
./comp/mfs/mfs_log
./comp/mfs/mfs_playback
./comp/mfs/mfs_query
./comp/mfs/mfs_smart
./comp/mfs/mfs_store
./comp/mfs/open-iscsi
./comp/mfs/soft_raid
./comp/mfs/test
./comp/mfs/toavi
./comp/module/
./comp/module/config
./comp/module/devlib
./comp/module/eqlib
./comp/module/fbkeyboard
./comp/module/playback
./comp/module/record
./comp/module/serial
./comp/module/upgrade
./comp/network/
./comp/network/cyasll
./comp/network/ddns
./comp/network/ftp_api
./comp/network/ftp_upgrade
./comp/network/gethostbyname
./comp/network/network
./comp/network/ntp
./comp/network/openssl
./comp/network/pppd
./comp/network/ssmtp
./comp/network/upnp
./comp/network/wpa_supplicant
./comp/pciv/pciv_msg
./comp/pciv/pciv_mpp
./comp/sdk/
./comp/sdk/inc
./comp/sdk/sdk_api
./comp/sdk/sdk_app
./comp/sdk/sdk_common
./comp/sdk/sdk_daemon
./comp/sdk/sdk_statmach
./comp/video
./comp/video/_include
./comp/video/_vconf
./comp/video/_vdec
./comp/video/_venc
./comp/video/_vo
./comp/video/_vpss
./comp/video/vdec
./comp/video/venc
./comp/video/vo
"

#==== public
svn_folder_list+="
./public/root
./public/root/sbin
./public/root/var
./public/root/var/run
./public/root/etc
./public/root/etc/init.d
./public/root/etc/udev
./public/hb2
./public/hb2/config
./public/hb2/config/etc
./public/hb2/config/etc/wifi
./public/hb2/config/etc/ppp
./public/hb2/config/etc/network
./public/hb2/logo
./public/usr
./public/usr/sbin
./public/usr/lib
./public/usr/data
./public/usr/data/ptz
./public/usr/data/ptz/protocol
./public/usr/data/video
./public/usr/data/gui
./public/usr/data/gui/res
./public/usr/data/gui/res/osd
./public/usr/data/gui/res/ptz
./public/usr/data/gui/res/num
./public/usr/data/gui/res/ptz_ctrl
./public/usr/bin
./public/usr/etc
./public/usr/etc/init.d
./public/usr/etc/udev
./public/usr/etc/udev/rules.d
./public/usr/etc/network
./public/usr/share
./public/usr/share/tabset
./public/usr/share/terminfo
./public/usr/share/terminfo/v
./public/web
"

#==== pc tools
svn_folder_list+="
./pc_tool/
./pc_tool/restore_maker
./pc_tool/upgrade_maker
./pc_tool/upgrade_unmaker
"
#svn_folder_list="comp build tool"
check_folder_list()
{
    ever_failed=0
    for dir in ${svn_folder_list}
    do
    check_folder ${dir}
    if [[ "$?" == 1 ]]
    then
        if [[ ever_failed -eq 0 ]]
        then
            ever_failed=1
        fi
    fi
    done
    if [[ ever_failed == 1 ]]
    then 
        return 1
    fi
    return 0
}

check_new_folder()
{
    SVN_LOG_FILE=svn_log.txt
    if [[ `grep "| (no author) | (no date) |" ${SVN_LOG_FILE}` ]]
    then
        echo "${ERROR_STR} Some folder is not readable, see svn_log.txt for more details" >> ${OUTPUT_FILE}
        return 1
    fi
    return 0
}

rm -rf ${OUTPUT_FILE}
check_new_folder
if [[ "$?" == 1 ]]
then
    exit 1
fi
check_folder_list

# vim:et:sw=4:ts=4

